package trainingcamp.day02.char_api;
public class 交换文字顺序标准版本 {
    public static void main(String[] args) {
        /*
         * 混淆一个字符串
         */
        String str = "新增本土确诊病例20和无症状感染者age";
        char[] chs = new char[str.length()];
        char min = '\u4E00';
        char max = '\u9FA5';
        for (int i = 1; i<str.length(); i+=2){
            char c1 = str.charAt(i-1);
            char c2 = str.charAt(i);
            //判断 c1 和 c2 是否在 min max 范围内
            //如果在范围内, 则交换存储, 否则不交换
            if((c1>=min && c1<=max) && (c2>=min && c2<=max)){
                chs[i-1] = c2;
                chs[i] = c1;
            }else{
                chs[i-1] = c1;
                chs[i] = c2;
            }
        }
        if (str.length() % 2 != 0){
            chs[chs.length-1] = str.charAt(str.length()-1);
        }
        System.out.println(chs);
    }
}